// <copyright file="Program.cs" company="SharpSTS">
// Copyright (c) 2007, 2008 All Right Reserved, http://sharpsts.com/
//
// This source is subject to the Microsoft Permissive License.
// Please see the License.txt file for more information.
// All other rights reserved.
//
// THIS CODE AND INFORMATION ARE PROVIDED "AS IS" WITHOUT WARRANTY OF ANY 
// KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
// PARTICULAR PURPOSE.
//
// </copyright>
// <author>Barry Dorrans</author>
// <email>barryd@idunno.org</email>
// <date>2008-06-20</date>
// <summary>Creates a command line host for the STS service..</summary>

namespace SharpSTS.CommandLine
{
    using System;
    using System.ServiceModel;
    using System.ServiceModel.Dispatcher;

    using Windows;

    /// <summary>
    /// Creates a command line host for the STS Services.
    /// </summary>
    public class Program
    {
        /// <summary>
        /// The command line STS host entry point.
        /// </summary>
        /// <param name="args">Command line arguments.</param>
        public static void Main(string[] args)
        {
            try
            {
                InformationCardSTSServiceHosts.Open();                
                try
                {
                    foreach (ServiceHost host in InformationCardSTSServiceHosts.ServiceHosts)
                    {
                        foreach (ChannelDispatcher cd in host.ChannelDispatchers)
                        {
                            foreach (EndpointDispatcher ed in cd.Endpoints)
                            {
                                Console.WriteLine("Listener = {0}\n    State = {1}", ed.EndpointAddress, cd.State);
                            }
                        }
                    }

                    // Wait until enter is pressed.
                    Console.Write("\n\nPress <ENTER> to terminate services");
                    Console.ReadLine();
                }
                catch (Exception ex)
                {
                    Console.Write(ex.ToString());
                }
                finally
                {
                    InformationCardSTSServiceHosts.Close();
                }
            }
            catch (Exception e)
            {
                Console.WriteLine("An unexpected fault was encountered:\n{0}", e);
            }
        }
    }
}
